#include <iostream>
#include <algorithm>

using namespace std;

typedef long long LL;

const int N = 1e5 + 10;

LL f[N];
int a[N];
int n, k;

int main()
{
	cin >> n >> k;
	for(int i = 1; i <= n; i++) cin >> a[i];
	sort(a + 1, a + 1 + n);
	for(int i = 2; i <= n; i++)
	{
		f[i] = a[i] * a[i] - a[i - 1] * a[i - 1];
		f[i] += f[i - 1];
	}
	LL ans = 0x3f3f3f3f3f3f3f3f;
	for(int i = 1; i + k - 1 <= n; i++)
	{
		int j = i + k - 1;
		ans = min(ans, f[j] - f[i]);
	}
	cout << ans << endl;
	return 0;
}

 
